Conditions | 1 |
Paths | 1 |
Total Lines | 116 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var chai = require('chai'); |
||
11 | describe('Template', function() { |
||
12 | before( function(done) { |
||
13 | Manager.instance.init() |
||
14 | .then(function () { |
||
15 | this.fixture = { |
||
16 | slug: fse.readFileSync(__dirname + '/fixtures/templates/slug.html', 'utf-8'), |
||
|
|||
17 | template: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf-8'), |
||
18 | articleEach: fse.readFileSync(__dirname + '/fixtures/templates/article-each-abe.html', 'utf-8'), |
||
19 | articlePrecontrib: fse.readFileSync(__dirname + '/fixtures/templates/article-precontribution.html', 'utf-8'), |
||
20 | templateKeys: fse.readFileSync(__dirname + '/fixtures/templates/article-keys.html', 'utf-8') |
||
21 | } |
||
22 | done() |
||
23 | |||
24 | }.bind(this)) |
||
25 | }); |
||
26 | |||
27 | /** |
||
28 | * getAbeImport |
||
29 | * |
||
30 | */ |
||
31 | it('cmsTemplates.template.getStructureAndTemplates()', function() { |
||
32 | var res = cmsTemplates.template.getStructureAndTemplates() |
||
33 | chai.expect(res.templates.length).to.be.above(1); |
||
34 | }); |
||
35 | |||
36 | /** |
||
37 | * getAbeImport |
||
38 | * |
||
39 | */ |
||
40 | it('cmsTemplates.template.getAbeImport()', function() { |
||
41 | var res = cmsTemplates.template.getAbeImport(this.fixture.template) |
||
42 | chai.expect(res).to.have.length(4); |
||
43 | }); |
||
44 | |||
45 | /** |
||
46 | * includePartials |
||
47 | * |
||
48 | */ |
||
49 | it('cmsTemplates.template.includePartials()', function() { |
||
50 | var template = cmsTemplates.template.includePartials(this.fixture.template) |
||
51 | chai.expect(template).to.contain("{{abe type='text' key='title' desc='titre' tab='default'}}"); |
||
52 | }); |
||
53 | |||
54 | /** |
||
55 | * cmsTemplates.template.getTemplate |
||
56 | * |
||
57 | */ |
||
58 | it('cmsTemplates.template.getTemplate()', function() { |
||
59 | var template = cmsTemplates.template.getTemplate('article') |
||
60 | chai.expect(template).to.contain("{{abe type='text' key='title' desc='titre' tab='default' order='1'}}"); |
||
61 | }); |
||
62 | |||
63 | /** |
||
64 | * cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist |
||
65 | * |
||
66 | */ |
||
67 | it('cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist()', function() { |
||
68 | var text = cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist("") |
||
69 | chai.expect(text).to.be.equal(`{{abe type="slug" source="{{name}}"}}\n`); |
||
70 | }); |
||
71 | |||
72 | /** |
||
73 | * cmsTemplates.template.setAbePrecontribDefaultValueIfDoesntExist |
||
74 | * |
||
75 | */ |
||
76 | it('cmsTemplates.template.setAbePrecontribDefaultValueIfDoesntExist()', function() { |
||
77 | var text = cmsTemplates.template.setAbePrecontribDefaultValueIfDoesntExist("") |
||
78 | chai.expect(text).to.be.equal(`{{abe type='text' key='name' desc='Name' required="true" tab="slug" visible="false"}}\n`); |
||
79 | }); |
||
80 | |||
81 | /** |
||
82 | * cmsTemplates.template.getAbePrecontribFromTemplates |
||
83 | * |
||
84 | */ |
||
85 | it('cmsTemplates.template.getAbePrecontribFromTemplates()', function() { |
||
86 | var precontrib = cmsTemplates.template.getAbePrecontribFromTemplates([{name: 'slug', template: this.fixture.slug}]) |
||
87 | chai.expect(precontrib.fields[0]).to.not.be.undefined; |
||
88 | }); |
||
89 | |||
90 | /** |
||
91 | * cmsTemplates.template.getAbeSlugFromTemplates |
||
92 | * |
||
93 | */ |
||
94 | it('cmsTemplates.template.getAbeSlugFromTemplates()', function() { |
||
95 | var slug = cmsTemplates.template.getAbeSlugFromTemplates([{name: 'slug', template: this.fixture.slug}]) |
||
96 | chai.expect(slug.slug).to.not.be.undefined; |
||
97 | }); |
||
98 | |||
99 | /** |
||
100 | * getTemplate |
||
101 | * |
||
102 | */ |
||
103 | it('cmsTemplates.template.execRequestColumns()', function() { // templateKeys |
||
104 | const pathTemplate = path.join(config.root, config.templates.url) |
||
105 | var ar = cmsTemplates.template.execRequestColumns(this.fixture.templateKeys) |
||
106 | chai.expect(ar.indexOf('abe_meta.date')).to.be.above(-1); |
||
107 | }); |
||
108 | |||
109 | /** |
||
110 | * cmsTemplates.insertDebugtoolUtilities |
||
111 | * |
||
112 | */ |
||
113 | it('cmsTemplates.insertDebugtoolUtilities()', function() { |
||
114 | var txt = cmsTemplates.insertDebugtoolUtilities('</body>'); |
||
115 | chai.expect(txt.length).to.above(10); |
||
116 | }); |
||
117 | |||
118 | /** |
||
119 | * cmsTemplates.encodeAbeTagAsComment |
||
120 | * |
||
121 | */ |
||
122 | it('cmsTemplates.encodeAbeTagAsComment()', function() { |
||
123 | var txt = cmsTemplates.encodeAbeTagAsComment(this.fixture.articleEach); |
||
124 | chai.expect(txt.indexOf('{')).to.equal(-1); |
||
125 | }); |
||
126 | }); |
||
127 |